home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 41.zip
/
BS1 part 41
/
Compute`s Amiga resource 1.adf
/
Source
/
X-Ray
/
X-Ray.c
Wrap
C/C++ Source or Header
|
1989-02-07
|
17KB
|
772 lines
/*
X-Ray
By Randy Thompson
Copyright 1989 COMPUTE! Publications, Inc.
All Rights Reserved
Last modified 01/31/89
Compile with Lattice C 5.0
lc -L -O X-Ray
*/
/*
Startup code for NOT opening a window when run from the Workbench.
*/
#include <stdio.h>
#include <fcntl.h>
#include <ios1.h>
#include <string.h>
#include <stdlib.h>
#include <workbench/startup.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <proto/dos.h>
#include <proto/exec.h>
#define MAXARG 32 /* maximum command line arguments */
#define QUOTE '"'
#define isspace(c) ((c == ' ')||(c == '\t') || (c == '\n'))
extern struct UFB _ufbs[];
int argc; /* arg count */
char **targv, *argv[MAXARG]; /* arg pointers */
#define MAXWINDOW 40
extern struct WBStartup *WBenchMsg;
void _main(line)
register char *line;
{
register char **pargv;
while (argc < MAXARG)
{
while (isspace(*line)) line++;
if (*line == '\0') break;
pargv = &argv[argc++];
if (*line == QUOTE)
{
*pargv = ++line; /* ptr inside quoted string */
while ((*line != '\0') && (*line != QUOTE)) line++;
if (*line == '\0') _exit(1);
else *line++ = '\0'; /* terminate arg */
}
else /* non-quoted arg */
{
*pargv = line;
while ((*line != '\0') && (!isspace(*line))) line++;
if (*line == '\0') break;
else *line++ = '\0'; /* terminate arg */
}
} /* while */
targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
main(argc,targv); /* call main function */
_exit(0);
}
/*
Beginning of main program.
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <graphics/gfxmacros.h>
#include <intuition/intuitionbase.h>
#define TITLE "X-Ray"
#define CREDIT "by Randy Thompson"
#define COPYRIGHT "X-Ray \xA9 1989 COMPUTE! Publications, Inc. All Rights Reserved."
#define VERT 0
#define HORIZ 1
#define NEXT 2
#define PREV 3
#define ENTER 4
#define MINWIDTH 160
#define MINHEIGHT 32
#define DEFWIDTH 200
#define DEFHEIGHT 100
#define LSHFTCLCK 0x8001
#define RSHFTCLCK 0x8002
#define ON TRUE
#define OFF FALSE
#define DEFTICK 200000;
#define FVPORT &(FScreen->ViewPort)
#define BBMAP &(BScreen->BitMap)
#define WRPORT Window->RPort
#define TIMREQ timerequest
void InitProgram();
void OpenXRWindow();
void AdjustProps();
BOOL AdjustLimits();
void DoGadget();
void IncScreen();
void DecScreen();
void SetScreen();
struct TIMREQ *OpenTimer();
void CloseTimer();
void QueueTimer();
void Follow();
void SwapIn();
void SwapOut();
void Quit();
struct IntuitionBase *IntuitionBase = NULL;
struct LayersBase *LayersBase = NULL;
struct GfxBase *GfxBase = NULL;
struct MsgPort *TimerPort = NULL;
struct TIMREQ *TimeRequest = NULL;
struct Screen *FScreen = NULL;
struct Screen *BScreen = NULL;
SHORT FWidth, FHeight;
SHORT BWidth, BHeight;
SHORT WWidth, WHeight;
ULONG Dx, Dy;
ULONG Micros;
ULONG Secs;
BOOL Timer;
USHORT Colors[255], NumReg;
USHORT chip PrevImageData[] = {
/* plane 1 */
0x03FF,0xFFF0,
0x03FF,0xFFF0,
0x03C0,0x00F0,
0x03C0,0x00F0,
0x03C0,0x00F0,
0x03F0,0x03F0,
0x03FC,0x0FF0,
0x03FF,0x3FF0,
0x03FF,0xFFF0,
0x03FF,0xFFF0,
/* plane 2 */
0x0000,0x0000,
0x0000,0x0000,
0x003F,0xFF00,
0x003F,0xFF00,
0x003F,0xFF00,
0x000F,0xFC00,
0x0003,0xF000,
0x0000,0xC000,
0x0000,0x0000,
0x0000,0x0000
};
struct Image PrevImage = {
-4,0,
28,10,2,
PrevImageData,
3,0,
NULL
};
struct Gadget PrevGadget = {
NULL,
0,0,
24,10,
GADGHCOMP | GADGIMAGE | GRELRIGHT,
GADGIMMEDIATE | RELVERIFY,
BOOLGADGET | GZZGADGET,
(APTR)&PrevImage,
NULL,
NULL,
0,
NULL,
PREV,
NULL
};
USHORT chip NextImageData[] = {
/* plane 1 */
0x03FF,0xFFF0,
0x03FF,0xFFF0,
0x03FF,0x3FF0,
0x03FC,0x0FF0,
0x03F0,0x03F0,
0x03C0,0x00F0,
0x03C0,0x00F0,
0x03C0,0x00F0,
0x03FF,0xFFF0,
0x03FF,0xFFF0,
/* plane 2 */
0x0000,0x0000,
0x0000,0x0000,
0x0000,0xC000,
0x0003,0xF000,
0x000F,0xFC00,
0x003F,0xFF00,
0x003F,0xFF00,
0x003F,0xFF00,
0x0000,0x0000,
0x0000,0x0000
};
struct Image NextImage = {
-4,0,
28,10,2,
NextImageData,
3,0,
NULL
};
struct Gadget NextGadget = {
NULL,
0,0,
24,10,
GADGHCOMP | GADGIMAGE | GRELRIGHT,
GADGIMMEDIATE | RELVERIFY,
BOOLGADGET | GZZGADGET,
(APTR)&NextImage,
NULL,
NULL,
0,
NULL,
NEXT,
NULL
};
USHORT chip EnterImageData[] = {
/* plane 1 */
0xF3FF,0xFFF0,
0xF3C3,0xF0F0,
0xF3F0,0xC3F0,
0xF3FC,0x0FF0,
0xF3FE,0x1FF0,
0xF3FC,0x0FF0,
0xF3F0,0xC3F0,
0xF3C3,0xF0F0,
0xF3FF,0xFFF0,
0xF3FF,0xFFF0,
/* plane 2 */
0x0000,0x0000,
0x003C,0x0F00,
0x000F,0x3C00,
0x0003,0xF000,
0x0001,0xE000,
0x0003,0xF000,
0x000F,0x3C00,
0x003C,0x0F00,
0x0000,0x0000,
0x0000,0x0000
};
struct Image EnterImage = {
-4,0,
28,10,2,
EnterImageData,
3,0,
NULL
};
struct Gadget EnterGadget = {
NULL,
0,0,
24,10,
GADGHCOMP | GADGIMAGE | GRELRIGHT,
GADGIMMEDIATE | RELVERIFY,
BOOLGADGET | GZZGADGET,
(APTR)&EnterImage,
NULL,
NULL,
0,
NULL,
ENTER,
NULL
};
struct Image HorizImage;
struct PropInfo HorizPropInfo = {
AUTOKNOB | FREEHORIZ,
0,0,
0,0,
0,0,
0,0,
0,0
};
struct Gadget HorizGadget = {
NULL,
1,0,
0,0,
GADGHCOMP | GRELBOTTOM | GRELWIDTH,
GADGIMMEDIATE | RELVERIFY | FOLLOWMOUSE,
PROPGADGET | GZZGADGET,
(APTR)&HorizImage,
NULL,
NULL,
0,
(APTR)&HorizPropInfo,
HORIZ,
NULL
};
struct Image VertImage;
struct PropInfo VertPropInfo = {
AUTOKNOB | FREEVERT,
0,0,
0,0,
0,0,
0,0,
0,0
};
struct Gadget VertGadget = {
NULL,
0,10,
0,0,
GADGHCOMP | GRELRIGHT | GRELHEIGHT,
GADGIMMEDIATE | RELVERIFY | FOLLOWMOUSE,
PROPGADGET | GZZGADGET,
(APTR)&VertImage,
NULL,
NULL,
0,
(APTR)&VertPropInfo,
VERT,
NULL
};
struct IntuiText XRIntuiText = {
2,1,
JAM1,
0,0,
NULL,
CREDIT,
NULL
};
struct MenuItem XRMenuItem = {
NULL,
0,0,
0,0,
ITEMTEXT | ITEMENABLED,
0,
(APTR)&XRIntuiText,
0,
NULL,
NULL
};
struct Menu XRMenu = {
NULL,
0,0,
48,10,
MENUENABLED,
COPYRIGHT,
&XRMenuItem
};
struct Window *Window = NULL;
struct NewWindow XRWindow =
{
0,0,
DEFWIDTH,DEFHEIGHT,
-1,-1,
CLOSEWINDOW | ACTIVEWINDOW | INACTIVEWINDOW | NEWSIZE |
GADGETUP | GADGETDOWN | MOUSEMOVE,
WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG | WINDOWSIZING | SIZEBRIGHT |
SIZEBBOTTOM | GIMMEZEROZERO | NOCAREREFRESH,
NULL,
NULL,
NULL,
NULL,
NULL,
MINWIDTH,MINHEIGHT,
0,0,
CUSTOMSCREEN
};
void main(argc, argv)
int argc;
char **argv;
{
register struct Screen *scr;
register BOOL bgone;
struct IntuiMessage *message;
ULONG tick, class;
USHORT qualifier, last_id;
APTR iaddress;
BOOL update = FALSE;
Timer=OFF;tick=DEFTICK;
if (argc==2) tick=atol(argv[1]);
if (tick==0) tick=1;
Secs=tick/1000000L;Micros=tick-(Secs*1000000L);
InitProgram();
FOREVER {
while (GetMsg(TimerPort)) {
if (BScreen!=FScreen) {
BltBitMapRastPort(BBMAP,Dx,Dy,WRPORT,0,0,WWidth,WHeight,0xC0);
QueueTimer(TimeRequest,Micros,Secs);
} else
Timer=OFF;
}
Wait (1<<Window->UserPort->mp_SigBit | 1<<TimerPort->mp_SigBit);
while ((message=(struct IntuiMessage *)GetMsg(Window->UserPort))) {
class=message->Class;
qualifier=message->Qualifier;
iaddress=message->IAddress;
ReplyMsg((struct Message *)message);
bgone=TRUE;
for (
scr=IntuitionBase->FirstScreen;
scr!=NULL;
scr=scr->NextScreen
) if (scr==BScreen) bgone=FALSE;
if (bgone) {BScreen=IntuitionBase->FirstScreen;SetScreen();}
switch (class) {
case GADGETUP:
DoGadget(((struct Gadget *)iaddress)->GadgetID,qualifier);
break;
case GADGETDOWN:
last_id=((struct Gadget *)iaddress)->GadgetID;
break;
case MOUSEMOVE:
update=TRUE;
break;
case ACTIVEWINDOW:
SwapIn();
SetWindowTitles(Window,-1,TITLE);
RefreshGadgets(Window->FirstGadget,Window,NULL);
break;
case INACTIVEWINDOW:
SwapOut();
RefreshGadgets(Window->FirstGadget,Window,NULL);
break;
case NEWSIZE:
AdjustProps();
break;
case CLOSEWINDOW:
SwapOut();
Quit();
break;
default:
break;
}
}
if (update) {
update=FALSE;
DoGadget(last_id,qualifier);
}
}
}
void InitProgram()
{
BYTE i;
if ((IntuitionBase=(struct IntuitionBase *)
OpenLibrary("intuition.library",0))==NULL)
Quit();
if ((LayersBase=(struct LayersBase *)
OpenLibrary("layers.library",0))==NULL)
Quit();
if ((GfxBase=(struct GfxBase *)
OpenLibrary("graphics.library",0))==NULL)
Quit();
if ((TimeRequest=OpenTimer())==NULL)
Quit();
FScreen=IntuitionBase->ActiveScreen;BScreen=FScreen;
NumReg=1<<((FScreen->ViewPort).RasInfo->BitMap->Depth);
for (i=0;i<NumReg;i++) Colors[i]=GetRGB4(FScreen->ViewPort.ColorMap,i);
OpenXRWindow();
SetWindowTitles(Window,TITLE,-1);
RefreshGadgets(Window->FirstGadget,Window,NULL);
QueueTimer(TimeRequest,Micros,Secs);
}
void OpenXRWindow()
{
struct Gadget *gadg;
if ((XRWindow.Width=DEFWIDTH)>FScreen->Width)
if (FScreen->Width>=MINWIDTH)
XRWindow.Width=FScreen->Width;
if ((XRWindow.Height=DEFHEIGHT)>FScreen->Height)
if (FScreen->Height>=MINHEIGHT)
XRWindow.Height=FScreen->Height;
XRWindow.Screen=FScreen;
if ((Window=(struct Window *)OpenWindow(&XRWindow))==NULL)
Quit();
SetMenuStrip(Window,&XRMenu);
HorizPropInfo.HorizPot=VertPropInfo.VertPot=0;
for (gadg=Window->FirstGadget;gadg!=NULL;gadg=gadg->NextGadget) {
switch (gadg->GadgetType) {
case (SYSGADGET | GZZGADGET | WDOWNBACK):
PrevGadget.LeftEdge=gadg->LeftEdge-24;
AddGadget(Window,&PrevGadget,0);
NextGadget.LeftEdge=PrevGadget.LeftEdge-24;
AddGadget(Window,&NextGadget,0);
EnterGadget.LeftEdge=NextGadget.LeftEdge-24;
AddGadget(Window,&EnterGadget,0);
break;
case (SYSGADGET | GZZGADGET | SIZING):
HorizGadget.TopEdge=gadg->TopEdge;
HorizGadget.Width=-gadg->Width;
HorizGadget.Height=gadg->Height;
AddGadget(Window,&HorizGadget,-1);
VertGadget.LeftEdge=gadg->LeftEdge;
VertGadget.Width=gadg->Width;
VertGadget.Height=-gadg->Height-10;
AddGadget(Window,&VertGadget,-1);
break;
}
}
if (!AdjustLimits()) Quit();
AdjustProps();
RefreshGadgets(Window->FirstGadget,Window,NULL);
SetAPen(WRPORT,0);SetOPen(WRPORT,0);
}
void AdjustProps()
{
WWidth=Window->Width-Window->BorderLeft-Window->BorderRight;
ModifyProp(
&HorizGadget,Window,NULL,
AUTOKNOB | FREEHORIZ,
HorizPropInfo.HorizPot,0,
(WWidth*0xFFFF)/BWidth,0
);
WHeight=Window->Height-Window->BorderTop-Window->BorderBottom;
ModifyProp(
&VertGadget,Window,NULL,
AUTOKNOB | FREEVERT,
0,VertPropInfo.VertPot,
0,(WHeight*0xFFFF)/BHeight
);
Dy=((ULONG)(BHeight-WHeight)*VertPropInfo.VertPot+(1L<<15))>>16;
Dx=((ULONG)(BWidth-WWidth)*HorizPropInfo.HorizPot+(1L<<15))>>16;
}
BOOL AdjustLimits()
{
SHORT maxwidth, maxheight;
FWidth=FScreen->Width;FHeight=FScreen->Height;
BWidth=BScreen->Width;BHeight=BScreen->Height;
if ((maxwidth=BWidth+Window->BorderLeft+Window->BorderRight)>FWidth)
maxwidth=FWidth;
if ((maxheight=BHeight+Window->BorderTop+Window->BorderBottom)>FHeight)
maxheight=FHeight;
if (maxwidth<Window->Width) {
SizeWindow(Window,maxwidth-Window->Width,0);
while (Window->Width!=maxwidth);
}
if (maxheight<Window->Height) {
SizeWindow(Window,0,maxheight-Window->Height);
while (Window->Height!=maxheight);
}
return((BOOL)WindowLimits(Window,0,0,maxwidth,maxheight));
}
void DoGadget(id,shift)
USHORT id, shift;
{
switch (id) {
case VERT:
Dy=((ULONG)(BHeight-WHeight)*VertPropInfo.VertPot+(1L<<15))>>16;
break;
case HORIZ:
Dx=((ULONG)(BWidth-WWidth)*HorizPropInfo.HorizPot+(1L<<15))>>16;
break;
case NEXT:
IncScreen();
break;
case PREV:
DecScreen();
break;
case ENTER:
if (BScreen!=FScreen) {
ScreenToFront(BScreen);
if (
((shift & LSHFTCLCK)==LSHFTCLCK) ||
((shift & RSHFTCLCK)==RSHFTCLCK)
) Follow();
}
break;
default:
break;
}
if (BScreen!=FScreen)
BltBitMapRastPort(BBMAP,Dx,Dy,WRPORT,0,0,WWidth,WHeight,0xC0);
}
void IncScreen()
{
struct Screen *VScreen;
VScreen=BScreen;
if ((BScreen=BScreen->NextScreen)==NULL)
BScreen=IntuitionBase->FirstScreen;
if (VScreen!=BScreen) SetScreen();
}
void DecScreen()
{
struct Screen *PrevScreen, *VScreen;
VScreen=BScreen;
for (
PrevScreen=IntuitionBase->FirstScreen;
(PrevScreen->NextScreen!=BScreen) && (PrevScreen->NextScreen!=NULL);
PrevScreen=PrevScreen->NextScreen
);
BScreen=PrevScreen;
if (VScreen!=BScreen) SetScreen();
}
void SetScreen()
{
RectFill(WRPORT,0,0,WWidth,WHeight);
if (BScreen==FScreen) SwapOut();
else {
SwapIn();
if (Timer==OFF) {
Timer=ON;
if (CheckIO(TimeRequest)) QueueTimer(TimeRequest,Micros,Secs);
}
}
if (!AdjustLimits()) Quit();
AdjustProps();
SetWindowTitles(Window,BScreen->Title,-1);
RefreshGadgets(Window->FirstGadget,Window,NULL);
}
struct TIMREQ *OpenTimer()
{
struct TIMREQ *tr;
if (
((TimerPort=(struct MsgPort *)CreatePort(0,0))==NULL) ||
((tr=(struct TIMREQ *)
CreateExtIO(TimerPort,sizeof(struct TIMREQ)))==NULL) ||
(OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)tr,0))
)
return(NULL);
else
return(tr);
}
void CloseTimer(tr)
struct TIMREQ *tr;
{
while (CheckIO(tr)==NULL) {
Wait (1<<TimerPort->mp_SigBit);
(void)GetMsg(TimerPort);
}
if (tr->tr_node.io_Device) CloseDevice((struct IORequest *)tr);
if (TimerPort!=NULL) DeletePort(TimerPort);
DeleteExtIO(tr,sizeof(struct TIMREQ));
}
void QueueTimer(tr,micros,secs)
struct TIMREQ *tr;
ULONG micros;
ULONG secs;
{
struct timeval delay;
delay.tv_secs=secs;
delay.tv_micro=micros;
tr->tr_time=delay;
tr->tr_node.io_Command=TR_ADDREQUEST;
SendIO((struct IORequest *)tr);
}
void Follow()
{
BYTE i;
struct Screen *scr;
SwapOut();
scr=FScreen;FScreen=BScreen;BScreen=scr;
NumReg=1<<((FScreen->ViewPort).RasInfo->BitMap->Depth);
for (i=0;i<NumReg;i++) Colors[i]=GetRGB4(FScreen->ViewPort.ColorMap,i);
ClearMenuStrip(Window);
CloseWindow(Window);
OpenXRWindow();
SetWindowTitles(Window,BScreen->Title,-1);
RefreshGadgets(Window->FirstGadget,Window,NULL);
}
void SwapIn()
{
LoadRGB4(FVPORT,(BScreen->ViewPort.ColorMap->ColorTable),NumReg);
}
void SwapOut()
{
LoadRGB4(FVPORT,(ULONG)Colors,NumReg);
}
void Quit()
{
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
if (LayersBase) CloseLibrary(LayersBase);
if (GfxBase) CloseLibrary(GfxBase);
if (Window) {ClearMenuStrip(Window);CloseWindow(Window);}
if (TimeRequest) CloseTimer(TimeRequest);
exit(0L);
}